package com.fulihui.wgj.consumer.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.fulihui.wgj.consumer.service.RegionService;
import com.fulihui.wgj.facade.service.region.WxRegionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * @author: LiuJie
 * @version: 2018/7/2 18:46
 * @description: 区域信息初始化
 */
@Service
@Slf4j
public class RegionServiceImpl implements RegionService {

    @Reference(version = "1.0.0")
    WxRegionService wxRegionService;

    private Map<String, String> regions;

    @PostConstruct
    public void init() {
        if (null == regions) {
            regions = wxRegionService.getAllRegionMap();
            log.info("Region 数据初始化,数据量= {} 条", regions.size());
        }
    }

    @Override
    public Map<String, String> getRegion() {
        init();
        return regions;
    }
}
